package com.fs.service.impl;


import com.fs.entity.Page;
import com.fs.entity.User;
import com.fs.entity.UserCondition;
import com.fs.mapper.UserMapper;
import com.fs.mapper.util.MybatisUtil;
import com.fs.service.UserService;

public class UserServiceImpl implements UserService {
    private UserMapper userMapper = MybatisUtil.getMapper(UserMapper.class);
    @Override
    public Page<User> queryByPage(int pageIndex, int pageSize) {
        Page<User> page = queryPageByCondition(pageIndex, pageSize, null);
        MybatisUtil.close();
        return  page;
    }

    @Override
    public Page<User> queryPageByCondition(int pageIndex, int pageSize, UserCondition userCondition) {
        Page<User> page = new Page<>();
        page.setPageIndex(pageIndex);
        page.setPageSize(pageSize);
        userCondition.setStartNo((pageIndex-1)*pageSize);
        userCondition.setPageSize(pageSize);
        page.setRecords(userMapper.selectPage(userCondition));
        page.setTotalCount(userMapper.count(userCondition));
        MybatisUtil.close();
        return page;
    }

    @Override
    public User queryById(int id) {
        return userMapper.selectById(id);
    }

    @Override
    public void updateUser(User user) {
        userMapper.updateById(user);
    }

    @Override
    public void deleteById(int id) {
        userMapper.deleteById(id);
    }

    @Override
    public void addUser(User user) {

    }
}
